import path from "path";
import fs from "fs";
import cjs from "@rollup/plugin-commonjs"
import ts from "rollup-plugin-typescript2"
// 获取根的路径
const packagePath = path.resolve(__dirname, "../../packages");
// 获取导报后的路径
const distPcgPath = path.resolve(__dirname, "../../dist/node_modules");

// 获取包的路径
export const resolvePcgPath = (name,isDist)=>{
    if(isDist){
        return `${distPcgPath}/${name}`
    }
    return `${packagePath}/${name}`
}


// 获取包的package.json的内容
export const getPackageJson = (name) => {
    const path = resolvePcgPath(name) + '/package.json'
    const content = fs.readFileSync(path,'utf-8')
    return JSON.parse(content)
}

// 获取基本插件
export const getBasePlugins = ({typescript = {}} = {})=>{
    return [cjs(),ts(typescript)]
}